<?php
class TokenComponent extends Component {
	var $controller;
	
	function startup(&$controller) {
		$this->controller =& $controller;
		$this->controller->set('token', $this);
	}
	
	function getTokenForMail($mailID, $time = null)
	{
		if(!$time){
			App::import('Model', 'Mailaddress');
			$mail = new Mailaddress();
			$time = $mail->field('modified', 'id = '.$mailID);
		}
		
		if($this->controller->name === 'Users'){
			$salt = Configure::read('salt.register');
		}elseif($this->controller->name === 'Mailaddresses'){
			$salt = Configure::read('salt.activate');
		}
		return md5((string)$salt.(string)strtotime($time));
	}
	function getTokenForFriend($friendID, $time = null)
	{
		if(!$time){
			App::import('Model', 'Friend');
			$friend = new Friend();
			$time = $friend->field('modified', 'id = '.$friendID);
		}
		
		$salt = Configure::read('salt.friend');
		return md5((string)$salt.(string)strtotime($time));
	}

}
?>
